//
//  Singleton.m
//  SXparent
//
//  Created by HuangSui on 16/10/24.
//  Copyright © 2016年 SuiXun. All rights reserved.
//

#import "Singleton.h"
#import "CWStarRateView.h"
#define Knum @"^[0-9]+$"
//#define Knum @"^[A-Za-z]+$"







@implementation Singleton

//全局变量
static id _instance = nil;
static NSString *identifier=@"yangkang";
//单例方法
+(instancetype)sharedSingleton{
    
    return [[self alloc] init];
}
//alloc会调用allocWithZone:
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    //只进行一次
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });
    return _instance;
}
//初始化方法
- (instancetype)init{
    // 只进行一次
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super init];
    });
    
    return _instance;
}
//copy在底层会调用copyWithZone:
- (id)copyWithZone:(NSZone *)zone{
    return  _instance;
}
+ (id)copyWithZone:(struct _NSZone *)zone{
    return  _instance;
}
+ (id)mutableCopyWithZone:(struct _NSZone *)zone{
    return _instance;
}
- (id)mutableCopyWithZone:(NSZone *)zone{
    return _instance;
}


#pragma mark ----YKButton
-(YKButton *)endButton:(UIColor *)color andTitle:(NSString *)str RequestSuccess:(btnAction)requestSuccess
{
    YKButton *button=[YKButton buttonWithType:UIButtonTypeCustom];
    if (color) {
        button.backgroundColor=color;
    }
    
    button.layer.masksToBounds=YES;
    button.layer.cornerRadius=5;
    button.layer.borderWidth=1;
    button.layer.borderColor=[UIColor clearColor].CGColor;
    [button setTitle:str forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font=[UIFont systemFontOfSize:17];
    [button addTarget:self action:@selector(endAction:) forControlEvents:UIControlEventTouchUpInside];
    button.block=requestSuccess;
    //    _btnAction=requestSuccess;
    return button;
}
-(void)endAction:(YKButton *)btn
{
    if (btn.block) {
        btn.block(btn);
    }
}

#pragma mark ----UILabel
-(UILabel *)myLabel:(UIColor *)color andTitle:(NSString *)str andFont:(CGFloat)font
{
    UILabel *lab=[[UILabel alloc]init];
    lab.numberOfLines=0;
    lab.text=str;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textColor=color;
    return lab;
}
-(UIScrollView *)myScrollViewWithFrame:(CGRect)frame withContentSize:(CGSize)size
{
    UIScrollView *myScrollView=[[UIScrollView alloc]initWithFrame:frame];
    myScrollView.contentSize=size;
    myScrollView.showsVerticalScrollIndicator = NO;
    myScrollView.showsHorizontalScrollIndicator = NO;
   
    
    if (@available(iOS 11.0,*)) {
        
        myScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else
    {
        
    }
    return myScrollView;
}
#pragma mark --UITextField
-(YKTextField *)myTextFieldsecure:(BOOL)secureTextEntry andkeyboardType:(UIKeyboardType)kt andplaceholder:(NSString *)str andLeftImage:(NSString *)imageStr RequestSuccess:(TFAction)requestSuccess
{
    YKTextField *text = [[YKTextField alloc]init];
    text.delegate = self;
    text.returnKeyType =UIReturnKeyDone;
    text.clearButtonMode = UITextFieldViewModeWhileEditing;
    text.autocorrectionType = UITextAutocorrectionTypeNo;
    text.secureTextEntry = secureTextEntry;
    //UIKeyboardTypeNumberPad,UIKeyboardTypeDefault
    text.keyboardType = kt;
    text.placeholder = str;
    text.backgroundColor=[UIColor whiteColor];
    text.layer.masksToBounds=YES;
    if (imageStr) {
        UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:imageStr]];
        text.leftView=image;
        text.leftViewMode = UITextFieldViewModeAlways;
    }else
    {
        text.layer.cornerRadius=5;
    }
    
    //字体大小(不设置默认是17)
    text.font = [UIFont systemFontOfSize:14];
    //    text.textColor = [UIColor redColor];
    //    //键盘外观
    //    text.keyboardAppearance=UIKeyboardAppearanceDefault;
    //    //系统默认透明
    //    text.backgroundColor=[UIColor whiteColor];
    //    //光标颜色
    //    text.tintColor=[UIColor redColor];
    
    //解决Placeholder 不居中问题(用的14）
    //    NSMutableParagraphStyle *style = [text.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];
    //    style.minimumLineHeight = text.font.lineHeight-(text.font.lineHeight-[UIFont systemFontOfSize:14.0].lineHeight)/2.0;
    //    text.attributedPlaceholder = [[NSAttributedString alloc] initWithString:str attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14.0],NSParagraphStyleAttributeName : style}];
    text.block=requestSuccess;
    return text;
}
//1
- (BOOL)textFieldShouldBeginEditing:(YKTextField *)textField
{
    LRLog(@"将要开始编辑");
    return YES;
}
//2
- (void)textFieldDidBeginEditing:(YKTextField *)textField
{
    LRLog(@"已经开始编辑");
}
//3
- (BOOL)textFieldShouldEndEditing:(YKTextField *)textField{
    
    LRLog(@"将要结束编辑");
    return YES;
}
//4
- (void)textFieldDidEndEditing:(YKTextField *)textField
{
    LRLog(@"已经结束编辑");
}
//5  这个代理里面的textField.text不可取  可能有部分等待转化的数据
//string记录的是每步输入的字符 range表示每步输入的字符(串)的位置和长度
//stringByReplacingCharactersInRange 方法可以得到屏幕输入框内显示的所有字符
-(BOOL)textField:(YKTextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    //得到输入框的内容
    //    NSString *toBeString=[textField.text stringByReplacingCharactersInRange:range withString:string];
    //        NSString* number= Knum;
    //        NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",number];
    //        return [numberPre evaluateWithObject:string];
    
    
    if (textField.block) {
        textField.block(textField,range,string);
    }
    return YES;
}
//6
- (BOOL)textFieldShouldClear:(YKTextField *)textField{
    
    LRLog(@"点击清除");
    textField.text=@"";
    
    if (textField.block) {
        textField.block(textField,NSMakeRange(0, 0),nil);
    }
    return YES;
}
//7
- (BOOL)textFieldShouldReturn:(YKTextField *)textField
{
    
    LRLog(@"点击结束");
    return [textField resignFirstResponder];
    
}
#pragma mark UITableView
-(ykTableView *)myTableViewWithFrame:(CGRect)frame withRefresh:(BOOL)refresh didSelect:(selectAction)didSelectRowAtIndexPath
{
    ykTableView *tableView = [[ykTableView alloc]initWithFrame:frame style:UITableViewStylePlain];
    tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    tableView.delegate=self;
    tableView.dataSource=self;
    tableView.backgroundColor=[UIColor clearColor];
    
    if (@available(iOS 11.0,*)) {
        tableView.estimatedRowHeight = 0;
        tableView.estimatedSectionHeaderHeight = 0;
        tableView.estimatedSectionFooterHeight = 0;
        tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else
    {
        //Fallback on earlier versons
    }
    
    if (refresh) {
        __weak __typeof(self) weakSelf = self;
        
        // 设置回调（一旦进入刷新状态就会调用这个refreshingBlock）
        tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            
            [weakSelf loadNewData:tableView];
        }];
        
        // 马上进入刷新状态
        [tableView.mj_header beginRefreshing];
        // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadMoreData方法）
        
        tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [weakSelf loadMoreData:tableView];
        }];
        // 设置了底部inset
        tableView.contentInset = UIEdgeInsetsMake(0, 0, 30, 0);
        // 忽略掉底部inset
        tableView.mj_footer.ignoredScrollViewContentInsetBottom = 30;
    }
    tableView.selectAction=didSelectRowAtIndexPath;
    return tableView;
    
}


#pragma mark 下拉刷新数据
-(void)loadNewData:(ykTableView *)tableView
{
    
    tableView.page=0;
    
    [tableView.mj_footer resetNoMoreData];
    [self getData:tableView.page andView:tableView];
}
#pragma mark 上拉加载更多数据
-(void)loadMoreData:(ykTableView *)tableView
{
    
    [self getData:tableView.page+1 andView:tableView];
}
-(void)getData:(int)page andView:(ykTableView *)tableView
{
    //测试
    sleep(2);
    
    //1请求失败
    [tableView.mj_header endRefreshing];
    [tableView.mj_footer endRefreshing];
    //    //2请求无数据（包括空数据）
    //    [tableView.mj_header endRefreshing];
    //    [tableView.mj_footer endRefreshing];
    //    [tableView.mj_footer endRefreshingWithNoMoreData];
    //    //3请求有实体数据
    //    tableView.page=page;
    //    [tableView.mj_header endRefreshing];
    //    [tableView.mj_footer endRefreshing];
    //    //3.1数据对应尾部(可以超页与无数据合并，此项就可以不要)
    //    [tableView.mj_footer endRefreshingWithNoMoreData];
    
    
}
#pragma mark TableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(ykTableView *)tableView
{
    return  tableView.dataArray.count;
}
- (NSInteger)tableView:(ykTableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *itemArr=tableView.dataArray[section];
    return itemArr.count;
}

- (UITableViewCell *)tableView:(ykTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    if (tableView.className) {
        
        if ([tableView.className isEqualToString:@"Type1"]) {
            UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className];
            //主标题+内容文字
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:tableView.className];
                UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, cell.contentView.frame.size.height-1, tableView.frame.size.width, 1)];
                [cell.contentView addSubview:lineLabel];
                lineLabel.backgroundColor=[UIColor colorF];
                lineLabel.tag=1993;
            }
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            cellData *cellObj=itemArr[indexPath.row];
            cell.textLabel.text=cellObj.text;
            cell.textLabel.font=[UIFont systemFontOfSize:12.0];
            cell.detailTextLabel.text=cellObj.detailText;
            cell.detailTextLabel.font=[UIFont systemFontOfSize:12.0];
            
            UILabel *lineLab=[cell viewWithTag:1993];
            if (indexPath.row==itemArr.count-1) {
                lineLab.hidden=YES;
            }else
            {
                lineLab.hidden=NO;
            }
            if ([cellObj.text isEqualToString:@"账户名"] ||[cellObj.text isEqualToString:@"联系人"] ||[cellObj.text isEqualToString:@"联系电话"] || [cellObj.text isEqualToString:@"地址"] || [cellObj.text isEqualToString:@"电动车品牌"]|| [cellObj.text isEqualToString:@"省市区"] || [cellObj.text isEqualToString:@"修理商"]|| [cellObj.text isEqualToString:@"门店名称"]|| [cellObj.text isEqualToString:@"账号"]|| [cellObj.text isEqualToString:@"电动车品牌"]) {
                cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            }
            else if ([cellObj.text isEqualToString:@"评分"])
                
            {
                CWStarRateView  *starView = [[CWStarRateView alloc] initWithFrame:CGRectMake(0, 0, 100, 16) numberOfStars:5];
                starView.scorePercent = 0.4;
                starView.allowIncompleteStar = YES;
                starView.hasAnimation = YES;
                cell.accessoryView=starView;
                
            }
            else
            {
                cell.accessoryType=UITableViewCellAccessoryNone;
            }
            
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            return cell;
        }
        else if ([tableView.className isEqualToString:@"Type2"])
        {
            UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className];
            //图片+主标题+内容文字
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:tableView.className];
                UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, cell.contentView.frame.size.height-1, tableView.frame.size.width, 1)];
                [cell.contentView addSubview:lineLabel];
                lineLabel.backgroundColor=[UIColor colorF];
                lineLabel.tag=1993;
            }
            
            
            
            
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            cellData *cellObj=itemArr[indexPath.row];
            cell.imageView.image=[UIImage imageNamed:cellObj.image];
            cell.textLabel.text=cellObj.text;
            cell.textLabel.font=[UIFont systemFontOfSize:14.0];
            cell.detailTextLabel.text=cellObj.detailText;
            cell.detailTextLabel.font=[UIFont systemFontOfSize:12.0];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            UILabel *lineLab=[cell viewWithTag:1993];
            if (indexPath.row==itemArr.count-1) {
                lineLab.hidden=YES;
            }else
            {
                lineLab.hidden=NO;
            }
            return cell;
        }
        else if ([tableView.className isEqualToString:@"Type3"])
        {
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            cellData *cellObj=itemArr[indexPath.row];
            
            UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className];
            //型号输入框
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:tableView.className];
                UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, cell.contentView.frame.size.height-1, tableView.frame.size.width, 1)];
                [cell.contentView addSubview:lineLabel];
                lineLabel.backgroundColor=[UIColor colorF];
                lineLabel.tag=1993;
            }
            UILabel *lineLab=[cell viewWithTag:1993];
            if (indexPath.row==itemArr.count-1) {
                lineLab.hidden=YES;
            }else
            {
                lineLab.hidden=NO;
            }
            
            
            YKTextField *myTF=[cell viewWithTag:710];
            [myTF removeFromSuperview];
            myTF=nil;
            //防止重用
            YKTextField *newTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入电动车型号" andLeftImage:nil RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
                
                NSString *toBeString=[textField.text stringByReplacingCharactersInRange:range withString:string];
                cellObj.text=toBeString;
            }];
            [cell.contentView addSubview:newTF];
            newTF.frame=CGRectMake(0, 0, SCREEN_WIDTH, 43);
            newTF.tag=710;
            newTF.text=cellObj.text;
            cell.accessoryType=UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            return cell;
        }
        else if ([tableView.className isEqualToString:@"Type4"])
        {
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            cellData *cellObj=itemArr[indexPath.row];
            
            UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className];
            //颜色输入框
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:tableView.className];
                
                UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, cell.contentView.frame.size.height-1, tableView.frame.size.width, 1)];
                [cell.contentView addSubview:lineLabel];
                lineLabel.backgroundColor=[UIColor colorF];
                lineLabel.tag=1993;
            }
            
            UILabel *lineLab=[cell viewWithTag:1993];
            if (indexPath.row==itemArr.count-1) {
                lineLab.hidden=YES;
            }else
            {
                lineLab.hidden=NO;
            }
            
            //消除复用
            YKTextField *myTF=[cell viewWithTag:710];
            [myTF removeFromSuperview];
            myTF=nil;
            
            YKTextField *newTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入电动车颜色" andLeftImage:nil RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
                NSString *toBeString=[textField.text stringByReplacingCharactersInRange:range withString:string];
                cellObj.text=toBeString;
                
            }];
            [cell.contentView addSubview:newTF];
            newTF.frame=CGRectMake(0, 0, SCREEN_WIDTH, 43);
            newTF.tag=710;
            newTF.text=cellObj.text;
            cell.accessoryType=UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            return cell;
        }
        else if ([tableView.className isEqualToString:@"TableViewCell"])
        {
            //管理员样式
            TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className forIndexPath:indexPath];
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            cellData *cellObj=itemArr[indexPath.row];
            cell.dataDic=cellObj;
            if (indexPath.row==itemArr.count-1) {
                cell.lineLab.hidden=YES;
            }else
            {
                cell.lineLab.hidden=NO;
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
        
        else if ([tableView.className isEqualToString:@"StoreCell"])
        {
            
            StoreCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className forIndexPath:indexPath];
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            StoreData *cellObj=itemArr[indexPath.row];
            cell.dataDic=cellObj;
            if (indexPath.row==itemArr.count-1) {
                cell.lineLab.hidden=YES;
            }
            else
            {
                cell.lineLab.hidden=NO;
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
        else if ([tableView.className isEqualToString:@"RepairerCell"])
        {
            
            RepairerCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className forIndexPath:indexPath];
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            repairerData *cellObj=itemArr[indexPath.row];
            cell.dataDic=cellObj;
            if (indexPath.row==itemArr.count-1) {
                cell.lineLab.hidden=YES;
            }
            else
            {
                cell.lineLab.hidden=NO;
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
        else if ([tableView.className isEqualToString:@"EvmCell"])
        {
            
            EvmCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className forIndexPath:indexPath];
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            EvmData *cellObj=itemArr[indexPath.row];
            cell.dataDic=cellObj;
            if (indexPath.row==itemArr.count-1) {
                cell.lineLab.hidden=YES;
            }
            else
            {
                cell.lineLab.hidden=NO;
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
        else if ([tableView.className isEqualToString:@"PoliceCell"])
        {
            
            PoliceCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className forIndexPath:indexPath];
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            policeData *cellObj=itemArr[indexPath.row];
            cell.dataDic=cellObj;
            if (indexPath.row==itemArr.count-1) {
                cell.lineLab.hidden=YES;
            }
            else
            {
                cell.lineLab.hidden=NO;
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
        else if ([tableView.className isEqualToString:@"PropertyCell"])
        {
            
            PropertyCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className forIndexPath:indexPath];
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            propertyData *cellObj=itemArr[indexPath.row];
            cell.dataDic=cellObj;
            if (indexPath.row==itemArr.count-1) {
                cell.lineLab.hidden=YES;
            }
            else
            {
                cell.lineLab.hidden=NO;
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
        else if ([tableView.className isEqualToString:@"MissCell"])
        {
            
            MissCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className forIndexPath:indexPath];
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            MissData *cellObj=itemArr[indexPath.row];
            cell.dataDic=cellObj;
            if (indexPath.row==itemArr.count-1) {
                cell.lineLab.hidden=YES;
            }
            else
            {
                cell.lineLab.hidden=NO;
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryNone;
            return cell;
        }
        else
        {
            TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableView.className forIndexPath:indexPath];
            NSArray *itemArr=tableView.dataArray[indexPath.section];
            cellData *cellObj=itemArr[indexPath.row];
            cell.dataDic=cellObj;
            if (indexPath.row==itemArr.count-1) {
                cell.lineLab.hidden=YES;
            }
            else
            {
                cell.lineLab.hidden=NO;
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
        
    }else
    {
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        //nib或代码自定义注册cell无需下面这几行代码
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, cell.contentView.frame.size.height-1, tableView.frame.size.width, 1)];
            lineLabel.backgroundColor=[UIColor colorF];
            lineLabel.tag=1993;
            [cell.contentView addSubview:lineLabel];
        }
        NSArray *itemArr=tableView.dataArray[indexPath.section];
        cellData *cellObj=itemArr[indexPath.row];
        cell.textLabel.text=cellObj.text;
        cell.textLabel.font=[UIFont systemFontOfSize:12.0];
        cell.detailTextLabel.text=cellObj.detailText;
        cell.detailTextLabel.font=[UIFont systemFontOfSize:12.0];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
}
-(void)tableView:(ykTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    if (tableView.selectAction) {
        tableView.selectAction(tableView,indexPath);
        
    }
    
}
-(CGFloat)tableView:(ykTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView.className isEqualToString:@"StoreCell"] ||[tableView.className isEqualToString:@"RepairerCell"] ||[tableView.className isEqualToString:@"EvmCell"])
    {
        return 60;
    }else if ([tableView.className isEqualToString:@"MissCell"])
    {
        return 80;
    }
    else
    {
        return 44;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    CGFloat height=0.0;
    if (section==0) {
        return height;
    }else
    {
        return 15;
    }
}
#pragma mark 相机相册
-(void)PhotoAction:(UIViewController *)vc RequestSuccess:(didFinish)requestSuccess
{
    
    myPicker *picker = [[myPicker alloc] init];
    
    __weak __typeof(self) weakSelf = self;
    
    UIAlertController *alertController=[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *albumAction=[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
        {
            
            
            // 返回相机类型下支持的媒体类型数组
            NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            // 判断数组中是否拥有(NSString *)kUTTypeImage元素
            if ([availableMediaTypes containsObject:(NSString *)kUTTypeImage])
            {
                // 图片类型可用
                
                
                // 返回用户对相册的授权状态
                PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary authorizationStatus];
                switch (photoAuthorStatus) {
                    case PHAuthorizationStatusAuthorized:
                    {
                        
                        //                            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                        
                        // 将资源类型设置为相册类型
                        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                        // 将媒体类型设置为图片类型和视频类型(数组中如果只写一个,图像选择控制器即只能选取图片/视频)
                        picker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
                        // 设置选取后的图片允许编辑
                        picker.allowsEditing = YES;
                        // 设置代理,需要遵守<UINavigationControllerDelegate, UIImagePickerControllerDelegate>两个协议
                        picker.delegate = weakSelf;
                        // 弹出图像选取控制器
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                            [vc presentViewController:picker animated:YES completion:nil];
                        });
                    }
                        break;
                    case PHAuthorizationStatusDenied:
                    {
                        
                    }
                        break;
                    case PHAuthorizationStatusNotDetermined:
                    {
                        
                        
                        // 用户没有选择是否授权使用
                        [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
                            if (status == PHAuthorizationStatusAuthorized) {
                                // 创建图像选取控制器对象
                                //                                    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                                
                                // 将资源类型设置为相册类型
                                picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                                // 将媒体类型设置为图片类型和视频类型(数组中如果只写一个,图像选择控制器即只能选取图片/视频)
                                picker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
                                // 设置选取后的图片允许编辑
                                picker.allowsEditing = YES;
                                // 设置代理,需要遵守<UINavigationControllerDelegate, UIImagePickerControllerDelegate>两个协议
                                picker.delegate = weakSelf;
                                // 弹出图像选取控制器
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    
                                    [vc presentViewController:picker animated:YES completion:nil];
                                });
                            }else{
                                
                            }
                        }];
                    }
                        break;
                    case PHAuthorizationStatusRestricted:
                    {
                        
                    }
                        break;
                    default:
                        break;
                }
            }
            else
            {
                // 图片类型不可用
            }
        }
        else
        {
            // 相机类型不可用
            
        }
        
    }];
    UIAlertAction *cameraAction=[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        // 相机类型可用
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            //kUTTypeImage(图片类型,细分为kUTTypeJPEG、kUTTypeGIF、kUTTypeLivePhoto等)
            //kUTTypeMovie(视频类型,细分为kUTTypeMovie、kUTTypeMP3、kUTTypeAVIMovie等)
            // 返回相机类型下支持的媒体类型数组
            NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
            // 判断数组中是否拥有(NSString *)kUTTypeImage元素
            if ([availableMediaTypes containsObject:(NSString *)kUTTypeImage])
            {
                // 图片类型可用
                
                // 返回用户对视频媒体类型的授权状态
                //                    AVMediaTypeVideo(视频媒体类型)
                //                    AVMediaTypeAudio(音频媒体类型)
                AVAuthorizationStatus authorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
                // 处理不同授权状态下的操作流程
                switch (authorizationStatus)
                {
                    case AVAuthorizationStatusNotDetermined:
                    {
                        // 用户没有选择是否授权使用
                        
                        // 以"弹窗要求用户选择是否授权"为例
                        
                        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                            if(granted)
                            {
                                // 用户授权使用
                                // 创建图像选取控制器对象
                                //                                    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                                
                                // 将资源类型设置为相机类型
                                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                                // 将媒体类型设置为图片类型和视频类型(数组中如果只写一个,图像选择控制器即只允许拍照/录像)
                                picker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
                                //                                picker.mediaTypes = @[(NSString *)kUTTypeImage];
                                // 设置拍照后的图片允许编辑
                                picker.allowsEditing = YES;
                                // 设置摄像图像品质,默认是UIImagePickerControllerQualityTypeMedium
                                picker.videoQuality = UIImagePickerControllerQualityTypeLow;
                                // 设置最长摄像时间,默认是10秒
                                picker.videoMaximumDuration = 30;
                                // 设置代理,需要遵守<UINavigationControllerDelegate, UIImagePickerControllerDelegate>两个协议
                                picker.delegate = weakSelf;
                                
                                // 弹出图像选取控制器
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    
                                    [vc presentViewController:picker animated:YES completion:nil];
                                });
                            }
                            else
                            {
                                // 用户禁止使用
                            }
                        }];
                        
                    }
                        break;
                    case AVAuthorizationStatusRestricted:
                    {
                        // 用户禁止使用,且授权状态不可修改,可能由于家长控制功能
                    }
                        break;
                    case AVAuthorizationStatusDenied:
                    {
                        // 用户已经禁止使用
                    }
                        break;
                    case AVAuthorizationStatusAuthorized:
                    {
                        // 用户已经授权使用
                        // 创建图像选取控制器对象
                        //                            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                        
                        // 将资源类型设置为相机类型
                        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                        // 将媒体类型设置为图片类型和视频类型(数组中如果只写一个,图像选择控制器即只允许拍照/录像)
                        picker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
                        //                        picker.mediaTypes = @[(NSString *)kUTTypeImage];
                        // 设置拍照后的图片允许编辑
                        picker.allowsEditing = YES;
                        // 设置摄像图像品质,默认是UIImagePickerControllerQualityTypeMedium
                        picker.videoQuality = UIImagePickerControllerQualityTypeLow;
                        // 设置最长摄像时间,默认是10秒
                        picker.videoMaximumDuration = 30;
                        // 设置代理,需要遵守<UINavigationControllerDelegate, UIImagePickerControllerDelegate>两个协议
                        picker.delegate = weakSelf;
                        // 弹出图像选取控制器
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                            [vc presentViewController:picker animated:YES completion:nil];
                        });
                        
                        
                    }
                        break;
                }
                
            }
            else
            {
                // 图片类型不可用
            }
            
        }
        else
        {
            // 相机类型不可用
            
        }
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:cameraAction];
    [alertController addAction:albumAction];
    
    [vc presentViewController:alertController animated:YES completion:nil];
    
    picker.didFinish =requestSuccess;
    //    _didFinish=requestSuccess;
    //    return picker;
    
}
// 操作完成
- (void)imagePickerController:(myPicker *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    
    // do something ...
    //    UIImagePickerControllerMediaType // 媒体类型（kUTTypeImage、kUTTypeMovie等）
    //    UIImagePickerControllerOriginalImage // 原始图片
    //    UIImagePickerControllerEditedImage // 编辑后图片
    //    UIImagePickerControllerCropRect // 裁剪尺寸
    //    UIImagePickerControllerReferenceURL // 引用相册的URL
    //    UIImagePickerControllerMediaMetadata // 拍照的元数据
    //    UIImagePickerControllerMediaURL // 媒体的URL
    //    UIImagePickerControllerLivePhoto // PHLivePhoto
    
    // 回收图像选取控制器
    [picker dismissViewControllerAnimated:YES completion:^{
        if (picker.didFinish) {
            picker.didFinish(picker,info);
        }
        else
        {
            LRLog(@"block丢失");
        }
    }];
}

// 操作取消
- (void)imagePickerControllerDidCancel:(myPicker *)picker
{
    [picker dismissViewControllerAnimated:YES completion:^{
        if (picker.didFinish) {
            picker.didFinish(picker,nil);
        }
        else
        {
            LRLog(@"block丢失");
        }
    }];
}

@end
